﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyCommerce.Business.Stores;

namespace MyCommerce.Presentation.Stores.Presenters
{
    public class SearchProductPresenter
    {
        private IViews.ISeachProduct vManagedView;

        public SearchProductPresenter(IViews.ISeachProduct managedView)
        {
            if (managedView == null)
            {
                throw new Exception("managedView cannot be null");
            }

            vManagedView = managedView;
            vManagedView.OnLoadView += new Innova.FoundationFramework.DataTypes.GenericEventHandler<string>(vManagedView_OnLoadView);
            vManagedView.OnSearch += new Innova.FoundationFramework.DataTypes.GenericEventHandler<string>(vManagedView_OnSearch);
            vManagedView.OnSave += new EventHandler(vManagedView_OnSave);
            vManagedView.OnCancel += new EventHandler(vManagedView_OnCancel);

        }

        void vManagedView_OnSearch(object sender, Innova.FoundationFramework.DataTypes.GenericEventArgs<string> e)
        {
            if (!string.IsNullOrEmpty(e.EventData.Trim()))
            {
                ProductManager pProductManager = new ProductManager();
                vManagedView.ColProduct = pProductManager.GetProductByModel(e.EventData.Trim());
            }
            
        }

        void vManagedView_OnLoadView(object sender, Innova.FoundationFramework.DataTypes.GenericEventArgs<string> e)
        {
            
        }

        void vManagedView_OnSave(object sender, EventArgs e)
        {
            vManagedView.CloseAndSetResult(true);
        }

        void vManagedView_OnCancel(object sender, EventArgs e)
        {
            vManagedView.CloseAndSetResult(false);
        }


    }
}
